package models

import (
	"fmt"
	"log"
	"time"
)

// InitData 用于向数据库插入默认的数据
func InitData() {
	// 插入默认用户
	users := []User{
		{Username: "admin", Password: "admin123", Phonenumber: "1234567890", Email: "admin@example.com"},
		{Username: "johndoe", Password: "password123", Phonenumber: "0987654321", Email: "johndoe@example.com"},
		{Username: "a", Password: "a", Phonenumber: "a", Email: "a@a.com"},
		{Username: "114514", Password: "q", Phonenumber: "q", Email: "q@q.com"},
	}

	// 存储用户ID
	var userIDs []int64

	for _, user := range users {
		// 插入用户并获取返回的userID
		userID, err := AddUser(user)
		if err != nil {
			log.Printf("Failed to insert user %s: %v", user.Username, err)
			continue
		}
		log.Printf("User %s inserted successfully", user.Username)

		// 保存用户ID
		userIDs = append(userIDs, userID)
	}

	// 插入默认地址
	addresses := []Address{
		{Addressee: "大力王", Phonenumber: "19198101515", Address: "广东省深圳市南山区深圳湾1号", IsDefault: false},
		{Addressee: "帅otto", Phonenumber: "15020040123", Address: "冬筑监狱牢底坐穿", IsDefault: true},
		{Addressee: "我是逆蝶", Phonenumber: "11451411451", Address: "深圳湾海底", IsDefault: false},
		{Addressee: "大力王", Phonenumber: "19198101515", Address: "广东省深圳市南山区深圳湾1号", IsDefault: false},
		{Addressee: "帅otto", Phonenumber: "15020040123", Address: "冬筑监狱牢底坐穿", IsDefault: true},
		{Addressee: "我是逆蝶", Phonenumber: "11451411451", Address: "深圳湾海底", IsDefault: false},
		{Addressee: "大力王", Phonenumber: "19198101515", Address: "广东省深圳市南山区深圳湾1号", IsDefault: false},
		{Addressee: "帅otto", Phonenumber: "15020040123", Address: "冬筑监狱牢底坐穿", IsDefault: true},
		{Addressee: "我是逆蝶", Phonenumber: "11451411451", Address: "深圳湾海底", IsDefault: false},
	}
	for _, userID := range userIDs {
		for _, address := range addresses {
			// 插入地址
			address.UserID = int(userID)
			_, err := AddAddress(address)
			if err != nil {
				fmt.Printf("用户 %d 插入地址失败: %v\n", userID, err)
				continue // 如果插入失败，跳过当前地址
			}
			fmt.Printf("用户 %d 插入地址成功: %s\n", userID, address.Address)
		}
	}

	// 插入默认商品
	// 必须先创造商品，不然购物车和订单表无法引用
	products := []Product{
		{ProductName: "全友家居 实木双人床", ImageURL: "/products/1/1.png", Price: 999.00, Weight: "120kg", Type1: "家居家具", Type2: "床", Date: "2021/1/24", FromPlace: "四川-成都", Quantity: 500, SalesVolume: 2200, Brand: "全友家居", Shop: "全友家居官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "全友家居 实木双人床 1.8米现代简约欧式风格卧室家具 带储物功能 可选配床垫"},
		{ProductName: "顾家家居 软包床", ImageURL: "/products/2/1.png", Price: 6999.00, Weight: "100kg", Type1: "家居家具", Type2: "床", Date: "2022/1/23", FromPlace: "浙江-杭州", Quantity: 300, SalesVolume: 800, Brand: "顾家家居", Shop: "顾家家居官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "顾家家居 软包床 1.8米现代简约布艺皮质大床 卧室家具带USB充电口 可选配床垫"},
		{ProductName: "全友家居 实木书桌", ImageURL: "/products/3/1.png", Price: 1299.00, Weight: "35kg", Type1: "家居家具", Type2: "桌子", Date: "2020/10/24", FromPlace: "四川-成都", Quantity: 800, SalesVolume: 2500, Brand: "全友家居", Shop: "全友家居官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "全友家居 实木书桌 1.2米现代简约欧式风格学习办公桌 带抽屉储物功能 可调节高度"},
		{ProductName: "宜家 白色多功能折叠餐桌", ImageURL: "/products/4/1.png", Price: 799.00, Weight: "20kg", Type1: "家居家具", Type2: "桌子", Date: "2021/1/24", FromPlace: "上海-闵行", Quantity: 1500, SalesVolume: 3800, Brand: "宜家", Shop: "宜家官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "宜家 白色多功能折叠餐桌 小户型适用 简约现代风格 可扩展桌面 餐厅客厅两用"},
		{ProductName: "艺难忘奶油风岩板餐桌", ImageURL: "/products/5/1.jpg", Price: 1069.00, Weight: "221kg", Type1: "家居家具", Type2: "餐桌", Date: "2023/12/17", FromPlace: "福建-福州", Quantity: 275, SalesVolume: 2593, Brand: "艺难忘", Shop: "艺难忘家具旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "艺难忘奶油风岩板餐桌轻奢现代简约家用小户型吃饭桌子长方形餐桌椅组合 店长推荐-餐桌1.2米+4椅"},
		{ProductName: "晨巢 岩板餐桌", ImageURL: "/products/6/1.jpg", Price: 749.00, Weight: "186kg", Type1: "家居家具", Type2: "餐桌", Date: "2022/7/3", FromPlace: "江西-赣州", Quantity: 768, SalesVolume: 50000, Brand: "晨巢", Shop: "晨巢旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "晨巢 岩板餐桌 实木餐桌椅组合现代简约可伸缩折叠吃饭桌子餐厅家具 12MM岩板餐桌-101皮椅款 1.35米一桌六椅"},
		{ProductName: "沐乐旭沙发", ImageURL: "/products/7/1.jpg", Price: 239.00, Weight: "151kg", Type1: "家居家具", Type2: "沙发", Date: "2023/11/27", FromPlace: "河南-商丘", Quantity: 388, SalesVolume: 4967, Brand: "沐乐旭", Shop: "沐乐旭凡品专卖店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "沐乐旭沙发客厅折叠两用沙发床出租房小户型防猫爪三人沙发 深灰色【店长推荐】 三人位 1.8m +抱枕"},
		{ProductName: "杜杜美家真皮沙发", ImageURL: "/products/8/1.jpg", Price: 1578.00, Weight: "174kg", Type1: "家居家具", Type2: "沙发", Date: "2022/11/5", FromPlace: "江西-赣州", Quantity: 744, SalesVolume: 2578, Brand: "杜杜美家", Shop: "杜杜美家旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "杜杜美家真皮沙发客厅2024新款现代简约扶手储物皮艺沙发A80#2.4米"},
		{ProductName: "米客米家 茶几", ImageURL: "/products/9/1.jpg", Price: 67.00, Weight: "54kg", Type1: "家居家具", Type2: "茶几", Date: "2023/5/5", FromPlace: "江苏-徐州", Quantity: 554, SalesVolume: 5126, Brand: "米客米家", Shop: "米客米家旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "米客米家 茶几现代简约小户型简易客厅迷你小尺寸桌子家用卧室角几边几 【双层款】100CM暖白色"},
		{ProductName: "洋意悦 简约茶几", ImageURL: "/products/10/1.jpg", Price: 276.00, Weight: "136kg", Type1: "家居家具", Type2: "茶几", Date: "2022/4/25", FromPlace: "江苏-徐州", Quantity: 1500, SalesVolume: 2492, Brand: "洋意悦", Shop: "洋意悦旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "洋意悦 简约茶几客厅家用边桌轻奢小户型茶几电视柜 60鱼肚白岩板+70钢化玻璃"},
		{ProductName: "海尔滚筒洗衣机", ImageURL: "/products/11/1.png", Price: 1585.88, Weight: "21.9kg", Type1: "大型家电", Type2: "洗衣机", Date: "2024/8/1", FromPlace: "广东-东莞", Quantity: 100, SalesVolume: 589, Brand: "海尔", Shop: "海尔官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "海尔滚筒洗衣机家用全自动超薄10kg大容量除菌MAX29"},
		{ProductName: "小米双区滚筒洗衣机", ImageURL: "/products/12/1.jpg", Price: 4999.00, Weight: "10.1kg", Type1: "大型家电", Type2: "洗衣机", Date: "2024/11/15", FromPlace: "北京-海淀", Quantity: 2024, SalesVolume: 1218, Brand: "小米", Shop: "小米官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "【重磅新品】小米米家双区双洗烘直驱变频滚筒洗衣机全自动家用"},
		{ProductName: "美的嵌入式家用冰箱", ImageURL: "/products/13/1.png", Price: 4999.00, Weight: "94kg", Type1: "大型家电", Type2: "冰箱", Date: "2024/4/1", FromPlace: "安徽", Quantity: 100, SalesVolume: 40000, Brand: "美的", Shop: "美的官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "美的480升十字对开双开四门大容量一级风冷无霜嵌入式家用冰箱"},
		{ProductName: "海尔统帅冰箱", ImageURL: "/products/14/1.png", Price: 1085.99, Weight: "53kg", Type1: "大型家电", Type2: "冰箱", Date: "2024/8/1", FromPlace: "山东-青岛", Quantity: 2000, SalesVolume: 1000, Brand: "海尔", Shop: "海尔官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "政府换新补贴海尔统帅218L三门节能租房宿舍家用超薄小冰箱官方"},
		{ProductName: "小米电视6 OLED", ImageURL: "/products/15/1.png", Price: 4999.00, Weight: "15.5kg", Type1: "大型家电", Type2: "电视", Date: "2020/1/24", FromPlace: "北京-海淀", Quantity: 300, SalesVolume: 500, Brand: "小米", Shop: "小米官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "小米电视6 OLED 55英寸4K超高清全面屏智能电视 AI语音遥控 双向蓝牙 智能家居控制中心"},
		{ProductName: "索尼Bravia XR A95K", ImageURL: "/products/16/1.png", Price: 12999.00, Weight: "23.5kg", Type1: "大型家电", Type2: "电视", Date: "2021/7/24", FromPlace: "上海", Quantity: 500, SalesVolume: 1200, Brand: "索尼", Shop: "索尼官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "索尼Bravia XR A95K 65英寸OLED电视 4K HDR 配备XR认知芯片 支持杜比视界和全景声"},
		{ProductName: "格力 大1匹 壁挂式空调", ImageURL: "/products/17/1.png", Price: 2799.00, Weight: "11kg", Type1: "大型家电", Type2: "空调", Date: "2024/5/24", FromPlace: "广东-珠海", Quantity: 3000, SalesVolume: 6000, Brand: "格力", Shop: "格力官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "格力 大1匹 壁挂式空调 一级能效 冷暖变频 智能遥控 静音节能 家用卧室客厅适用"},
		{ProductName: "美的 3匹 柜式空调", ImageURL: "/products/18/1.png", Price: 5999.00, Weight: "45kg", Type1: "大型家电", Type2: "空调", Date: "2023/10/24", FromPlace: "广东-佛山", Quantity: 800, SalesVolume: 2200, Brand: "美的", Shop: "美的官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "美的 3匹 柜式空调 一级能效 冷暖变频 大风量 快速制冷热 智能WIFI控制 客厅大空间适用"},
		{ProductName: "美的立式消毒柜", ImageURL: "/products/19/1.png", Price: 1699.00, Weight: "35kg", Type1: "小型家电", Type2: "消毒柜", Date: "2020/10/24", FromPlace: "广东-佛山", Quantity: 200, SalesVolume: 3500, Brand: "美的", Shop: "美的官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "美的立式消毒柜家用大容量双层碗碟架紫外线高温杀菌烘干一体机厨房电器"},
		{ProductName: "方太嵌入式消毒柜", ImageURL: "/products/20/1.png", Price: 2999.00, Weight: "45kg", Type1: "小型家电", Type2: "消毒柜", Date: "2019/2/24", FromPlace: "浙江-宁波", Quantity: 150, SalesVolume: 2800, Brand: "方太", Shop: "方太官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "方太嵌入式消毒柜100L大容量家用厨房餐具消毒机高温臭氧双重杀菌带烘干功能"},
		{ProductName: "美的立式塔扇", ImageURL: "/products/21/1.png", Price: 399.00, Weight: "4.5kg", Type1: "小型家电", Type2: "风扇", Date: "2024/5/24", FromPlace: "广东-佛山", Quantity: 500, SalesVolume: 8000, Brand: "美的", Shop: "美的官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "美的立式塔扇家用静音可调摇头多功能冷暖两用落地扇夏季空调伴侣"},
		{ProductName: "小米直流变频落地扇", ImageURL: "/products/22/1.png", Price: 599.00, Weight: "6.2kg", Type1: "小型家电", Type2: "风扇", Date: "2022/1/24", FromPlace: "北京-海淀", Quantity: 3000, SalesVolume: 600, Brand: "小米", Shop: "小米官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "小米直流变频落地扇3级能效智能遥控7羽叶大风量低噪节能电风扇家用客厅卧室"},
		{ProductName: "科沃斯 地宝X1 OMNI", ImageURL: "/products/23/1.png", Price: 3999.00, Weight: "4.5kg", Type1: "小型家电", Type2: "扫地机器人", Date: "2019/1/24", FromPlace: "江苏-苏州", Quantity: 1000, SalesVolume: 2800, Brand: "科沃斯", Shop: "科沃斯官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "科沃斯 地宝X1 OMNI 智能扫地机器人 激光导航 自动洗拖布 全自动基站 遥控APP控制"},
		{ProductName: "小米 扫地机器人Pro", ImageURL: "/products/24/1.png", Price: 2499.00, Weight: "3.8kg", Type1: "小型家电", Type2: "扫地机器人", Date: "2022/11/24", FromPlace: "北京-海淀", Quantity: 2000, SalesVolume: 4500, Brand: "小米", Shop: "小米官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "小米 扫地机器人Pro LDS激光导航 智能规划路径 大吸力湿拖一体机 米家APP远程控制 定时预约清扫"},
		{ProductName: "真我Neo7", ImageURL: "/products/25/1.png", Price: 2099.00, Weight: "189.5g", Type1: "数码", Type2: "手机", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 1919, SalesVolume: 810, Brand: "Realme真我", Shop: "Realme真我旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "realme真我Neo7 天玑9300+旗舰芯 7000mAh泰坦电池 6000nit护眼电竞直屏 智能游戏AI手机 12+256GB星舰"},
		{ProductName: "iphone16", ImageURL: "/products/26/1.png", Price: 6268.00, Weight: "190.8g", Type1: "数码", Type2: "手机", Date: "2024/9/10", FromPlace: "广东-深圳", Quantity: 20033, SalesVolume: 114514, Brand: "apple", Shop: "机御旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "【顺丰包邮】Apple/苹果iPhone 16新款5G手机 官方正品 全新国行 旗舰店"},
		{ProductName: "macbook air", ImageURL: "/products/27/1.jpg", Price: 7954.00, Weight: "1.2kg", Type1: "数码", Type2: "电脑", Date: "2024/1/1", FromPlace: "广东-深圳", Quantity: 1000, SalesVolume: 1300, Brand: "apple", Shop: "apple旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "Apple/苹果AI笔记本/2024 MacBook Air 13.6英寸 M3 (8+8核) 16G 256G深空灰色电脑 MC8G4CH/A"},
		{ProductName: "华硕天选5", ImageURL: "/products/28/1.jpg", Price: 6566.00, Weight: "2.6kg", Type1: "数码", Type2: "电脑", Date: "2024/12/12", FromPlace: "广东-深圳", Quantity: 500, SalesVolume: 2400, Brand: "华硕", Shop: "华硕旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "华硕天选5 国家补贴20%15.6英寸高性能游戏本 笔记本电脑(锐龙7 R7-8845H 16G 512G RTX4050 高色域)灰"},
		{ProductName: "小新Pro16", ImageURL: "/products/29/1.jpg", Price: 5999.00, Weight: "2569", Type1: "数码", Type2: "电脑", Date: "2024/12/16", FromPlace: "广东-深圳", Quantity: 3050, SalesVolume: 5003, Brand: "联想", Shop: "联想旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "联想笔记本电脑小新Pro16 2024 AI超能本 高性能标压酷睿Ultra5 16寸轻薄本 32G 1T 2.5K屏 游戏"},
		{ProductName: "WD SSD固态硬盘", ImageURL: "/products/30/1.jpg", Price: 458.00, Weight: "30g", Type1: "数码", Type2: "电脑配件", Date: "2024/4/6", FromPlace: "广东-深圳", Quantity: 1200, SalesVolume: 1030, Brand: "西部数据", Shop: "西部数据旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "西部数据（WD）SSD固态硬盘 M.2接口 SN770 PCIe4.0（NVMe协议）笔记本电脑游戏硬盘 AI"},
		{ProductName: "ROG 主板", ImageURL: "/products/31/1.jpg", Price: 5471.00, Weight: "0.5g", Type1: "数码", Type2: "电脑配件", Date: "2024/11/3", FromPlace: "广东-深圳", Quantity: 3500, SalesVolume: 2000, Brand: "ROG", Shop: "ROG旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "ROG MAXIMUS Z890 APEX 主板 支持 CPU 285K/265K/265KF (Intel Z890/LGA 1851）"},
		{ProductName: "罗技游戏鼠标", ImageURL: "/products/32/1.jpg", Price: 88.00, Weight: "54g", Type1: "数码", Type2: "外设设备", Date: "2024/12/14", FromPlace: "广东-深圳", Quantity: 2800, SalesVolume: 3040, Brand: "罗技", Shop: "罗技旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "罗技（G）G102 游戏鼠标 白色 RGB鼠标 吃鸡鼠标 绝地求生 轻量化设计 G102第二代"},
		{ProductName: "雷柏机械键盘", ImageURL: "/products/33/1.jpg", Price: 154.00, Weight: "266g", Type1: "数码", Type2: "外设设备", Date: "2024/5/9", FromPlace: "广东-深圳", Quantity: 8000, SalesVolume: 5030, Brand: "雷柏", Shop: "雷柏旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "雷柏（Rapoo） V500PRO 有线背光机械键盘 104键全尺寸游戏电竞笔记本电脑多媒体办公吃"},
		{ProductName: "AOC 2K显示屏", ImageURL: "/products/34/1.jpg", Price: 1033.00, Weight: "2.1kg", Type1: "数码", Type2: "外设设备", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 600, SalesVolume: 2003, Brand: "AOC", Shop: "AOC旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "AOC 27英寸 2K HDR400 IPS 原生180Hz  1ms 10Bit 满血小金刚MAX 旋转升降 游戏电竞"},
		{ProductName: "小米路由器", ImageURL: "/products/35/1.jpg", Price: 78.00, Weight: "200g", Type1: "数码", Type2: "外设设备", Date: "2024/7/9", FromPlace: "广东-深圳", Quantity: 2200, SalesVolume: 1503, Brand: "小米", Shop: "小米旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "小米双频千兆路由器4A千兆 家用高速无线路由百兆/千兆5G宿舍wifi 穿墙路由器 【标配】小米路由器4C"},
		{ProductName: "绿联USB", ImageURL: "/products/36/1.png", Price: 25.00, Weight: "20g", Type1: "数码", Type2: "外设设备", Date: "2024/3/11", FromPlace: "广东-深圳", Quantity: 800, SalesVolume: 500, Brand: "绿联", Shop: "绿联旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "绿联（UGREEN）WiFi6免驱 USB无线网卡台式机专用 无线WiFi接收器5G双频 台式笔记本电脑网络随身WiFi发射器 【300M - WiFi6】2.4G单频 - 内置天线"},
		{ProductName: "腾达路由器", ImageURL: "/products/37/1.jpg", Price: 85.00, Weight: "121g", Type1: "数码", Type2: "外设设备", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 2500, SalesVolume: 3000, Brand: "腾达", Shop: "腾达旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "Tenda腾达 AC10 双千兆无线路由器 游戏路由 全千兆有线端口 5G双频 1200M智能穿墙路"},
		{ProductName: "男式 T 恤", ImageURL: "/products/38/1.jpg", Price: 116.00, Weight: "220g", Type1: "男装/女装/童装", Type2: "男装", Date: "2024/9/1", FromPlace: "广东-东莞", Quantity: 1000, SalesVolume: 5008, Brand: "梦琦琇", Shop: "梦琦琇旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "梦琦琇男式 T 恤常规版型短袖圆领口袋"},
		{ProductName: "森马牛仔裤", ImageURL: "/products/39/1.jpg", Price: 139.00, Weight: "500g", Type1: "男装/女装/童装", Type2: "男装", Date: "2024/12/2", FromPlace: "浙江-杭州", Quantity: 2000, SalesVolume: 1000, Brand: "森马", Shop: "森马旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "森马（Semir）牛仔裤男森柔牛仔2024冬新款长裤复古做旧宽松直筒裤子"},
		{ProductName: "森马牛仔裤", ImageURL: "/products/39/1.jpg", Price: 139.00, Weight: "500g", Type1: "男装/女装/童装", Type2: "男装", Date: "2024/12/2", FromPlace: "浙江-杭州", Quantity: 2000, SalesVolume: 1000, Brand: "森马", Shop: "森马旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "森马（Semir）牛仔裤男森柔牛仔2024冬新款长裤复古做旧宽松直筒裤子"},
		{ProductName: "波司登羽绒服", ImageURL: "/products/40/1.jpg", Price: 219.00, Weight: "500g", Type1: "男装/女装/童装", Type2: "男装", Date: "2024/1/2", FromPlace: "广东-深圳", Quantity: 1000, SalesVolume: 5040, Brand: "波司登", Shop: "波司登旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "波司登（BOSIDENG）秋冬季轻薄羽绒服男款羽绒马甲短款V领内胆保暖百搭背心B40130001 尊贵蓝5456 M 175/96A"},
		{ProductName: "Dokotoo无袖背心裙", ImageURL: "/products/41/1.jpg", Price: 233.00, Weight: "300g", Type1: "男装/女装/童装", Type2: "女装", Date: "2024/7/20", FromPlace: "福建-福州", Quantity: 300, SalesVolume: 4300, Brand: "Dokotoo", Shop: "Dokotoo旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "Dokotoo 女式 2024 春夏 V 领纽扣无袖背心裙迷你连衣裙休闲背心裙带口袋"},
		{ProductName: "siliteelon女式系扣衬衫", ImageURL: "/products/42/1.jpg", Price: 196.00, Weight: "150g", Type1: "男装/女装/童装", Type2: "女装", Date: "2024/9/10", FromPlace: "山东-青岛", Quantity: 500, SalesVolume: 2650, Brand: "siliteelon", Shop: "siliteelon旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "siliteelon 女式系扣衬衫连衣裙衬衫长袖衬衫 V 领纯色休闲束腰上衣带口袋"},
		{ProductName: "罗蒙女式时尚风衣", ImageURL: "/products/43/1.jpg", Price: 582.00, Weight: "200g", Type1: "男装/女装/童装", Type2: "女装", Date: "2024/10/12", FromPlace: "广东-佛山", Quantity: 400, SalesVolume: 3050, Brand: "罗蒙", Shop: "罗蒙旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "罗蒙（ROMON）风衣女中长款春装2024春秋季新款宽松韩版英伦风外套百搭气质上衣"},
		{ProductName: "摇粒绒卫衣男女童", ImageURL: "/products/44/1.jpg", Price: 91.00, Weight: "400g", Type1: "男装/女装/童装", Type2: "童装", Date: "2024/11/14", FromPlace: "北京-海淀", Quantity: 600, SalesVolume: 4004, Brand: "mipo", Shop: "mipo旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "mipo【防静电】24年春秋款休闲立领摇粒绒卫衣男女童"},
		{ProductName: "真维斯女童外套", ImageURL: "/products/45/1.jpg", Price: 284.00, Weight: "300g", Type1: "男装/女装/童装", Type2: "童装", Date: "2024/10/12", FromPlace: "上海", Quantity: 700, SalesVolume: 5003, Brand: "真维斯", Shop: "真维斯旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "真维斯女童外套2024秋冬款儿童卫衣加绒加厚衣服中大童连帽开衫女孩秋装"},
		{ProductName: "班尼路男童裤子", ImageURL: "/products/46/1.jpg", Price: 80.00, Weight: "100g", Type1: "男装/女装/童装", Type2: "童装", Date: "2024/10/13", FromPlace: "广东-惠州", Quantity: 1200, SalesVolume: 9004, Brand: "班尼路", Shop: "班尼路旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "班尼路（Baleno）男童裤子冬季2024加绒加厚儿童秋冬款保暖冬装长裤男孩运动卫裤"},
		{ProductName: "娇兰粉底液", ImageURL: "/products/47/1.jpg", Price: 320.00, Weight: "50g", Type1: "美妆/个护清洁", Type2: "美妆", Date: "2024/10/14", FromPlace: "山东-青岛", Quantity: 1500, SalesVolume: 1200, Brand: "娇兰", Shop: "法国娇兰旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "娇兰（Guerlain）金钻修颜粉底液0N(光泽透亮)35ml遮瑕提亮生日圣诞礼物"},
		{ProductName: "MAC口红", ImageURL: "/products/48/1.jpg", Price: 189.00, Weight: "10g", Type1: "美妆/个护清洁", Type2: "美妆", Date: "2024/5/3", FromPlace: "上海-徐汇", Quantity: 2000, SalesVolume: 1500, Brand: "MAC", Shop: "MAC官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "MAC Macximal 丝滑哑光 - 女士天鹅绒泰迪熊 - 0.15 盎司口红"},
		{ProductName: "毛戈平 光韵臻颜双色遮瑕膏", ImageURL: "/products/49/1.jpg", Price: 264.00, Weight: "4g", Type1: "美妆/个护清洁", Type2: "美妆", Date: "2024/8/6", FromPlace: "上海", Quantity: 150, SalesVolume: 1200, Brand: "毛戈平", Shop: "丝芙兰官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "毛戈平 光韵（MAOGEPING LIGHT）臻颜双色遮瑕膏轻薄 遮瑕 圣诞节礼物 4G,901"},
		{ProductName: "NARS大白饼", ImageURL: "/products/50/1.jpg", Price: 437.00, Weight: "10g", Type1: "美妆/个护清洁", Type2: "美妆", Date: "2024/7/7", FromPlace: "上海", Quantity: 300, SalesVolume: 100000, Brand: "NARS", Shop: "NARS官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "NARS大白饼全明星套装持妆粉饼散粉蜜粉定妆不卡粉（套装已含赠品）"},
		{ProductName: "上海药皂硫磺除螨液体香皂", ImageURL: "/products/51/1.jpg", Price: 37.90, Weight: "500g", Type1: "美妆/个护清洁", Type2: "个护清洁", Date: "2024/6/23", FromPlace: "上海", Quantity: 600, SalesVolume: 500000, Brand: "上海药皂", Shop: "上海药皂官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "上海药皂硫磺除螨液体香皂500g洗发洗头沐浴洗手洗澡露液膏清洁男女通用"},
		{ProductName: "宝莹洗衣液", ImageURL: "/products/52/1.jpg", Price: 199.00, Weight: "5kg", Type1: "美妆/个护清洁", Type2: "个护清洁", Date: "2024/2/11", FromPlace: "广东-佛山", Quantity: 1400, SalesVolume: 60000, Brand: "宝莹", Shop: "汉高家清旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "宝莹（Persil）进口洗衣液9大酵素4.4L清香型99%除菌除螨抑菌强效去污护色家庭装"},
		{ProductName: "佳洁士香氛锁白牙膏", ImageURL: "/products/53/1.jpg", Price: 12.21, Weight: "120g", Type1: "美妆/个护清洁", Type2: "个护清洁", Date: "2024/8/3", FromPlace: "广东-佛山", Quantity: 4000, SalesVolume: 500000, Brand: "佳洁士", Shop: "宝洁官方旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "佳洁士香氛锁白牙膏美白去黄去牙渍含氟防蛀清新口气白桃味120g"},
		{ProductName: "Nike女鞋", ImageURL: "/products/54/1.jpg", Price: 505.00, Weight: "300g", Type1: "女鞋/轻奢/珠宝", Type2: "女鞋", Date: "2024/6/14", FromPlace: "广东-深圳", Quantity: 260, SalesVolume: 5006, Brand: "nike", Shop: "Nike旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "耐克 （NIKE）2024年女子WMNS AIR JORDAN 1 LOW篮球鞋 DC0774-162 36.5"},
		{ProductName: "asics女鞋", ImageURL: "/products/55/1.jpg", Price: 355.00, Weight: "326g", Type1: "女鞋/轻奢/珠宝", Type2: "女鞋", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 300, SalesVolume: 3007, Brand: "asics", Shop: "asics旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "亚瑟士ASICS女鞋缓震回弹跑鞋透气运动鞋舒适网面跑步鞋 GEL - CONTEND 4 米色/藕粉 37"},
		{ProductName: "卡地亚戒指", ImageURL: "/products/56/1.jpg", Price: 5168.00, Weight: "10g", Type1: "女鞋/轻奢/珠宝", Type2: "珠宝", Date: "2024/7/3", FromPlace: "广东-深圳", Quantity: 1500, SalesVolume: 9876, Brand: "卡地亚", Shop: "卡地亚旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "卡地亚（Cartier）戒指男女同款3.6毫米宽LOVE结婚对戒情侣婚戒 预售1 B4085200 18"},
		{ProductName: "周大福手镯", ImageURL: "/products/57/1.jpg", Price: 2404.00, Weight: "50g", Type1: "女鞋/轻奢/珠宝", Type2: "珠宝", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 1200, SalesVolume: 5432, Brand: "周大福", Shop: "周大福旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "周大福圣诞礼物珠宝首饰古风叮当镯白月光和田玉手镯生日礼物送礼EOV14 55mm"},
		{ProductName: "adidas男鞋", ImageURL: "/products/58/1.jpg", Price: 386.00, Weight: "322g", Type1: "男鞋/背包/户外", Type2: "男鞋", Date: "2024/5/18", FromPlace: "广东-深圳", Quantity: 400, SalesVolume: 800, Brand: "adidas", Shop: "adidas旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "阿迪达斯（adidas）男女运动鞋轻便耐磨休闲老爹鞋透气缓震跑步鞋  白 41"},
		{ProductName: "anta男鞋", ImageURL: "/products/59/1.jpg", Price: 296.00, Weight: "356g", Type1: "男鞋/背包/户外", Type2: "男鞋", Date: "2024/12/1", FromPlace: "广东-深圳", Quantity: 500, SalesVolume: 1500, Brand: "anta", Shop: "anta旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "安踏AT2002 丨Y2K复古潮流跑步鞋男冬季新款银色运动鞋时尚男鞋子"},
		{ProductName: "小米双肩包", ImageURL: "/products/60/1.jpg", Price: 88.00, Weight: "212g", Type1: "男鞋/背包/户外", Type2: "背包", Date: "2024/1/22", FromPlace: "广东-深圳", Quantity: 900, SalesVolume: 1000, Brand: "小米", Shop: "小米旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "小米（MI）经典商务双肩包简约商务笔记本电脑背包男女学生书包双肩背包黑色"},
		{ProductName: "迪卡侬背包", ImageURL: "/products/61/1.jpg", Price: 89.00, Weight: "179g", Type1: "男鞋/背包/户外", Type2: "背包", Date: "2024/1/24", FromPlace: "广东-深圳", Quantity: 1200, SalesVolume: 2000, Brand: "迪卡侬", Shop: "迪卡侬旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "迪卡侬双肩包书包学生户外徒步登山旅行淡米灰20升新老随机发2663476"},
		{ProductName: "米其林轮胎", ImageURL: "/products/62/1.jpg", Price: 434.00, Weight: "11.2kg", Type1: "汽车/汽车用品", Type2: "汽车用品", Date: "2024/12/17", FromPlace: "广东-深圳", Quantity: 4004, SalesVolume: 9004, Brand: "米其林", Shop: "米其林旗舰店", ReviewsNumber: 0, ReviewsGrade: 0.0, Title: "米其林（MICHELIN）汽车轮胎 205/55R16 91V 耐越 ENERGY MILE 适配朗逸/速腾/卡罗拉"},
	}

	for _, product := range products {
		_, err := AddProduct(product)
		if err != nil {
			// log.Printf("Failed to insert product %s: %v", product.ProductName, err)
		} else {
			// log.Printf("Product %s inserted successfully", product.ProductName)
		}
	}


	// 向购物车表插入数据（为每个用户创建购物车）
	for _, userID := range userIDs {
		// 插入购物车
		_, err := db.Exec(`
			INSERT INTO carts (user_id, total_amount) 
			VALUES (?, ?)`, userID, 0.0)
		if err != nil {
			log.Printf("Failed to insert cart for user ID %d: %v", userID, err)
			continue
		}

		// 获取该用户的购物车ID，使用 user_id 来查找
		var cartID int
		err = db.QueryRow("SELECT user_id FROM carts WHERE user_id = ?", userID).Scan(&cartID)
		if err != nil {
			log.Printf("Failed to get cart ID for user ID %d: %v", userID, err)
			continue
		}

		// 添加商品到购物车
		cartItems := []struct {
			ProductID 	int
			Quantity  	int
			Price     	float64
		}{
			{ProductID: 12, Price: 4999.00, Quantity: 11},// ProductName: "小米双区滚筒洗衣机", 
			{ProductID: 15, Price: 4999.00, Quantity: 45}, // ProductName: "小米电视6 OLED",
			{ProductID: 24, Price: 2499.00, Quantity: 14}, // ProductName: "小米 扫地机器人Pro",
		}

		for _, item := range cartItems {
			_, err := db.Exec("INSERT INTO cart_items (cart_id, product_id, price, quantity, status) VALUES (?, ?, ?, ?, ?)",
				cartID, item.ProductID, item.Price, item.Quantity, "未支付")
			if err != nil {
				log.Printf("Failed to add product %d to cart for user ID %d: %v", item.ProductID, userID, err)
			} else {
				log.Printf("Product %d added to cart for user ID %d", item.ProductID, userID)
			}
		}
	}

	// 向订单表插入数据（为每个用户创建订单）
	for _, userID := range userIDs {
		// 插入订单数据
		orderDate := time.Now() // 设置当前时间为订单日期
		_, err := db.Exec("INSERT INTO orders (user_id, order_date, status) VALUES (?, ?, ?)",
			userID, orderDate, "已支付")
		if err != nil {
			log.Printf("Failed to insert order for user ID %d: %v", userID, err)
			continue
		}
		// 获取刚插入的订单ID
		var orderID int
		// 获取在同一个数据库连接上下文中刚插入 ID
		err = db.QueryRow("SELECT last_insert_rowid()").Scan(&orderID)
		if err != nil {
			log.Printf("Failed to get order ID for user ID %d: %v", userID, err)
			continue
		}

		// 这个的orderDate会重合，所以第二次插入会失败
		// err = db.QueryRow("SELECT user_id FROM orders WHERE user_id = ? AND order_date = ?", userID, orderDate).Scan(&orderID)

		// 插入第二单数据
		delay := time.Millisecond * 1000 // 延迟 1 秒
		orderDate2 := orderDate.Add(delay)
		_, err = db.Exec("INSERT INTO orders (user_id, order_date, status) VALUES (?, ?, ?)",
			userID, orderDate2, "已支付")
		if err != nil {
			log.Printf("Failed to insert order for user ID %d: %v", userID, err)
			continue
		}
		// 获取刚插入的订单ID
		var orderID2 int
		err = db.QueryRow("SELECT last_insert_rowid()").Scan(&orderID2)
		if err != nil {
			log.Printf("Failed to get order ID for user ID %d: %v", userID, err)
			continue
		}

		// 添加商品到订单
		orderItems1 := []struct {
			ProductID 	int
			Price     	float64
			Quantity  	int
			IsCommented	bool
		}{
			{ProductID: 12, Price: 4999.00, Quantity: 24, IsCommented: true},// ProductName: "小米双区滚筒洗衣机", 
			{ProductID: 24, Price: 2499.00, Quantity: 114, IsCommented: true}, // ProductName: "小米 扫地机器人Pro",
			{ProductID: 35, Price: 78.00, Quantity: 514, IsCommented: false},// ProductName: "小米路由器", 
			} 

		// 添加商品到订单
		orderItems2 := []struct {
			ProductID 	int
			Price     	float64
			Quantity  	int
			IsCommented	bool
		}{
			{ProductID: 12, Price: 4999.00, Quantity: 78, IsCommented: true},// ProductName: "小米双区滚筒洗衣机", 
			{ProductID: 60, Price: 88.00, Quantity: 9527, IsCommented: false},
		} 

		// 添加商品到订单
		for _, item := range orderItems1 {
			_, err := db.Exec("INSERT INTO order_items (order_id, product_id, price, quantity, status, is_commented) VALUES (?, ?, ?, ?, ?, ?)",
				orderID, item.ProductID, item.Price, item.Quantity, "已支付", item.IsCommented)
			if err != nil {
				log.Printf("Failed to add product %d to order %d: %v", item.ProductID, orderID, err)
			} else {
				log.Printf("Product %d added to order %d", item.ProductID, orderID)
			}
		}

		// 添加商品到订单
		for _, item := range orderItems2 {
			_, err := db.Exec("INSERT INTO order_items (order_id, product_id, price, quantity, status, is_commented) VALUES (?, ?, ?, ?, ?, ?)",
				orderID2, item.ProductID, item.Price, item.Quantity, "已支付", item.IsCommented)
			if err != nil {
				log.Printf("Failed to add product %d to order %d: %v", item.ProductID, orderID2, err)
			} else {
				log.Printf("Product %d added to order %d", item.ProductID, orderID2)
			}
		}
	}	

	// 向收藏夹里插入数据
	for _, userID := range userIDs {

		_, err := db.Exec(`
			INSERT INTO favorites (user_id)
			VALUES (?)`, userID)
		if err != nil {
			log.Printf("用户 %d 添加收藏夹失败: %v", userID, err)
			continue
		}

		// 获取该用户的收藏夹ID， 使用 user_id 来查找
		var favoriteID int
		err = db.QueryRow("SELECT user_id FROM favorites WHERE user_id = ?", userID).Scan(&favoriteID)
		if err != nil {
			log.Printf("用户 %d 获取收藏夹ID失败: %v", userID, err)
			continue
		}

		// 添加商品到收藏夹
		favoriteItems := []struct {
			ProductID   int
			CollectDate time.Time
		}{
			{ProductID: 1, CollectDate: time.Now()},
			{ProductID: 2, CollectDate: time.Now()},
			{ProductID: 3, CollectDate: time.Now()},
		}

		for _, item := range favoriteItems {
			_, err = db.Exec(`INSERT INTO favorite_items (favorite_id, product_id, collectdate) VALUES (?, ?, ?)`,
				favoriteID, item.ProductID, time.Now())
			if err != nil {
				log.Printf("用户 %d 添加商品 %d 到收藏夹失败: %v", userID, item.ProductID, err)
			} else {
				log.Printf("用户 %d 成功添加商品 %d 到收藏夹", userID, item.ProductID)
			}
		}
	}

	// 添加测试评论数据
	testComments := []struct {
		UserID    int
		ProductID int
		OrderID   int
		Content   string
		Rating    int
	}{
		{
			UserID:    1,
			ProductID: 1,
			OrderID:   1,
			Content:   "很好的商品，质量不错！",
			Rating:    5,
		},
		{
			UserID:    2,
			ProductID: 1,
			OrderID:   2,
			Content:   "性价比很高，推荐购买",
			Rating:    4,
		},
		{
			UserID:    1,
			ProductID: 2,
			OrderID:   3,
			Content:   "一般般，还可以接受",
			Rating:    3,
		},
	}

	for _, comment := range testComments {
		_, err := AddComment(comment.UserID, comment.ProductID, comment.OrderID, comment.Content, comment.Rating)
		if err != nil {
			log.Printf("添加评论失败: %v", err)
		}
	}
}
